/*
 * @Author: Zhouhai 497675647@qq.com
 * @Date: 2022-10-08 11:45:40
 * @LastEditors: Zhouhai 497675647@qq.com
 * @LastEditTime: 2022-10-08 11:59:52
 */
import { CustomFormConfig, TSelect } from "@/type.d/formItems";
import { ProFormSelect } from "@ant-design/pro-components";

const getEnumValueByKey: (enumtype?: string, enumValue?: Record<string, Record<string, any>[]>) => any[] = (enumtype, enumValue) => {
    let re = [{ dictLabel: '主目录', dictValue: 0, children: {} }];
    if (enumtype && enumValue && enumValue[enumtype]) {
      const value = enumValue[enumtype]
      re = [{ dictLabel: '主目录', dictValue: 0, children: value }];
    }
    const result = re.map((item) => {
      return {
        label: item.dictLabel,
        value: item.dictValue
      }
    })
  
    return result;
  }

  

export const RenderSelect: (itemconfig: CustomFormConfig, disabled: boolean, enumValue?: Record<string, Record<string, any>[]>) => JSX.Element = (itemconfig, disabled, enumValue) => {
    const placeholder = disabled ? "" : (itemconfig?.placeholder || `请输入${itemconfig.title}`);
    const config = itemconfig.config as TSelect
    return <ProFormSelect
      placeholder={placeholder}
      key={itemconfig.fieldId}
      options={getEnumValueByKey(config?.enumType, enumValue)}
      width="md"
      colProps={{ md: 8, xl: 6 }}
      name={itemconfig.fieldId}
      label={itemconfig.title} params={undefined} debounceTime={undefined} request={undefined} valueEnum={undefined} />
  }